<template>
  <div class="login-box">
    <a-form
    class="form-box"
    :model="formState"
    name="basic"
    :label-col="{ span: 8 }"
    :wrapper-col="{ span: 16 }"
    autocomplete="off"
    @finish="onFinish"
    @finishFailed="onFinishFailed"
  >
    <a-form-item
      label="Username"
      name="username"
      :rules="[{ required: true, message: 'Please input your username!' }]"
    >
      <a-input v-model:value="formState.username" />
    </a-form-item>

    <a-form-item
      label="Password"
      name="password"
      :rules="[{ required: true, message: 'Please input your password!' }]"
    >
      <a-input-password v-model:value="formState.password" />
    </a-form-item>

    <a-form-item name="remember" :wrapper-col="{ offset: 8, span: 16 }">
      <a-checkbox v-model:checked="formState.remember">Remember me</a-checkbox>
    </a-form-item>

    <a-form-item :wrapper-col="{ offset: 8, span: 16 }">
      <a-button type="primary" html-type="submit">登 录</a-button>
    </a-form-item>
  </a-form>
  </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router';
import { defineComponent, reactive } from 'vue';
import {login} from '@/api/api'
import { setToken } from "@/utils/token"

const router = useRouter()

interface FormState {
  username: string;
  password: string;
  remember: boolean;
}
const formState = reactive<FormState>({
  username: '13811111111',
  password: '246810',
  remember: true,
});
const onFinish = async (values: any) => {
  let params = {
    mobile: formState.username,
    code: formState.password
  }
  let res = await login(params)
  setToken(res.data.token)
  console.log('Success:', values);
  router.push('/home')
};

const onFinishFailed = (errorInfo: any) => {
  console.log('Failed:', errorInfo);
};
</script>

<style lang="scss" scoped>
.login-box{
  position: relative;
  width: 100%;
  height: 100%;
  background-color: #fff;
  .form-box{
    position: absolute;
    padding: 30px;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    border: 1px solid #e6e6e6;
    border-radius: 5px;
    background-color: #fff;
  }
}
</style>